// <com.woyouqiu.Copyright>
// --------------------------------------------------------------
// <copyright>上海有求网络科技有限公司 2015</copyright>
// <Solution>Vecen.BangChuang</Solution>
// <Project>Vecen.BangChuang.EntityFrameworkCore</Project>
// <FileName>ProductCategoriesDataBuilder.cs</FileName>
// <CreateTime>2017-05-04 0:04</CreateTime>
// <Author>何苗</Author>
// <Email>hemiao@woyouqiu.com</Email>
// <log date="2017-05-04 0:04" version="00001">创建</log>
// --------------------------------------------------------------
// </com.woyouqiu.Copyright>

using System.Linq;
using Vecen.BangChuang.BangChuang.Products;

namespace Vecen.BangChuang.EntityFrameworkCore.Seed.BangChuang {
    public class ProductCategoriesDataBuilder {
        private readonly BangChuangDbContext _context;

        public ProductCategoriesDataBuilder(BangChuangDbContext context) {
            _context = context;
        }

        public void Create() {
            CreateCategory("文具");
            CreateCategory("珠宝");
            _context.SaveChanges();
        }

        private void CreateCategory(string name) {
            if(!_context.ProductCategories.Any(c => c.Name == name)) {
                _context.ProductCategories.Add(new ProductCategory()
                    {Name = name, ProductType = ProductType.Jewelry.ToString()});
            }
        }
    }
}